#!/usr/bin/env python

##########################################################################
# File Name: main.py
# Author: baohua
# Mail: liubaohuachina@163.com
# Create Time: 2020/03/24 09:20:43
# Version: 1.0
# Description: 
##########################################################################

import tornado.web
import tornado.ioloop
from tornado.options import options, define, parse_command_line

from sitebase.config import config
from sitebase.settings import app_settings, server_settings
from urls import urls

define("port", default=config['SERVER_PORT'], help="run on given port", type=int)


def main():
    "run the server"
    parse_command_line()
    if config['DEBUG']:
        print("Server (re)starts running in 'debug' mode at port %d\n"
              "Automatic loading, sql logging are turned on" %
              options.port)
    application = tornado.web.Application(urls, **app_settings)
    server = tornado.httpserver.HTTPServer(application, **server_settings)
    server.listen(options.port)
    tornado.ioloop.IOLoop.current().start()


if "__main__" == __name__:
    main()
